<?php

defined('BASEPATH') OR exit('No direct script access allowed');

class Adminapi_service {
	
	protected $CI;

	public function __construct()
    {	
        $this->CI =& get_instance();
		$this->CI->load->model('Admin_m');
		$this->CI->load->model('Adminlog_m');
		$this->CI->load->library('session');
    }



	/**
    *总后台登录
    *@param where 条件
    */
	public function getAdminByNicknameAndPassword($where){
		$result=$this->CI->Admin_m->select($where);
		if($result){
			$this->CI->session->set_userdata(array('admin'=>$result[0]));//存session
			$data['success'] = success();
			$data['admin_id'] = $result[0]['admin_id'];
			$data['tooken'] = jiami($result[0]['admin_id']);
			//登录日志
			$log['admin_id']=$result[0]['admin_id'];
			$log['log_info']='管理员登录';
			$log['log_ip']=$_SERVER["REMOTE_ADDR"];//访问者IP
			$log['log_time']=time();
        	$this->CI->Adminlog_m->insert($log);
		}else{
			$data['success'] = error(4012);
		}
		return $data;
	}


	

}